//
//  GraduationProjectTests.m
//  GraduationProjectTests
//
//  Created by Sylar on 16/4/13.
//  Copyright © 2016年 伍宏伟. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "AFNetworking.h"

#define WAIT do {\
[self expectationForNotification:@"Test" object:nil handler:nil];\
[self waitForExpectationsWithTimeout:2 handler:nil];\
} while (0);

#define NOTIFY \
[[NSNotificationCenter defaultCenter]postNotificationName:@"Test" object:nil];

@interface GraduationProjectTests : XCTestCase

@end

@implementation GraduationProjectTests


//城市单元测试
-(void)testCityJSONReturnSuccess
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"114d66be22bc4545b01f614bcd66ffff" forHTTPHeaderField:@"apikey"];
    
    NSString *urlString  = @"http://apis.baidu.com/heweather/pro/weather?city=beijing";
    
     NSURL *url = [NSURL URLWithString:urlString];
    
    [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"responseObject:%@",responseObject);
        XCTAssertNotNil(responseObject, @"返回出错");
        NOTIFY //继续执行
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"error:%@",error);
        XCTAssertNil(error, @"请求出错");
        NOTIFY
    }];
    WAIT
}


//景区单元测试
-(void)testSeneryJSONReturnSuccess
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"114d66be22bc4545b01f614bcd66ffff" forHTTPHeaderField:@"apikey"];
    
    NSString *urlString  = @"http://apis.baidu.com/heweather/pro/attractions?cityid=CN10101010018A";
    
    NSURL *url = [NSURL URLWithString:urlString];
    
    [manager GET:url.absoluteString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"responseObject:%@",responseObject);
        XCTAssertNotNil(responseObject, @"返回出错");
        NOTIFY //继续执行
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"error:%@",error);
        XCTAssertNil(error, @"请求出错");
        NOTIFY
    }];
    WAIT

}
@end
